#!/bin/sh
### BEGIN INIT INFO
# Provides:          pwrtray-backend
# Required-Start:    $syslog $local_fs dbus bluetooth
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: pwrtray-backend daemon
# Description:       Tiny power control daemon
### END INIT INFO

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
NAME=pwrtray-backend
DAEMON="$(which $NAME)"
PIDFILE="/run/pwrtray/pwrtray-backend.pid"
DESC="tiny power control daemon"

. /lib/lsb/init-functions

case "$1" in
	start)
		log_begin_msg "Starting $DESC: $NAME"
		start-stop-daemon --start --quiet --pidfile $PIDFILE \
			--oknodo --exec "$DAEMON" -- \
			-B -P $PIDFILE
		log_end_msg $?
		;;
	stop)
		log_begin_msg "Stopping $DESC: $NAME"
		start-stop-daemon --stop --quiet --pidfile $PIDFILE \
			--name "$NAME"
		RES=$?
		rm -f $PIDFILE
		log_end_msg $RES
		;;
	restart|reload|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "Usage $0 [start|stop|restart|reload|force-reload]"
		exit 1
		;;
esac

exit 0
